package com.jiahua.admin.biz.dao.impl;

import java.util.List;
import java.util.UUID;

import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.jiahua.admin.biz.dao.InventoryItemDao;
import com.jiahua.user.biz.model.InventoryItem;

public class InventoryItemDaoImpl extends HibernateDaoSupport implements InventoryItemDao {

	final Logger logger = Logger.getLogger(InventoryItemDaoImpl.class.getName());

	@Override
	public boolean saveProduct(InventoryItem inventoryItem) {
		boolean result = true;
		
		//System.out.println("inventoryItem.getImage().length : " + inventoryItem.getImage().length);

		try {
			inventoryItem.setInventoryItemID(UUID.randomUUID().toString());
			getHibernateTemplate().save(inventoryItem);
			logger.info("InventoryItemDaoImpl save successful.");
		} catch (DataAccessException e) {
			result = false;
			e.printStackTrace();
		} catch (Exception e) {
			result = false;
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public List<InventoryItem> listInventoryItem() {
		return getHibernateTemplate().find("from InventoryItem");
	}

	@Override
	public InventoryItem getInventoryItemById(String id) {
		return getHibernateTemplate().get(InventoryItem.class, id);
	}
}
